Test Series - Data Structure

Test Number 57/115

Q: What will be the height of a balanced full binary tree with 8 leaves?
A. 8
B. 5
C. 6
D. 4
Solution: A balanced full binary tree with l leaves has height h, where h = log2l + 1.
So, the height of a balanced full binary tree with 8 leaves = log28 + 1 = 3 + 1 = 4.
Q: The balance factor of a node in a binary tree is defined as _____
A. addition of heights of left and right subtrees
B. height of right subtree minus height of left subtree
C. height of left subtree minus height of right subtree
D. height of right subtree minus one
Solution: For a node in a binary tree, the difference between the heights of its left subtree and right subtree is known as balance factor of the node.
Q: A binary tree is balanced if the difference between left and right subtree of every node is not more than ____
A. 1
B. 0
C. 2
D. 3
Solution: In a balanced binary tree the heights of two subtrees of every node never differ by more than 1.
Q:  Which of the following tree data structures is not a balanced binary tree?
A. AVL tree
B. Red-black tree
C. Splay tree
D. B-tree
Solution: All the tree data structures given in options are balanced, but B-tree can have more than two children.All the tree data structures given in options are balanced, but B-tree can have more than two children.
Q: Balanced binary tree with n items allows the lookup of an item in ____ worst-case time.
A. O(log n)
B. O(nlog 2)
C. O(n)
D. O(1)
Solution: Searching an item in balanced binary is fast and worst-case time complexity of the search is O(log n).
Q: Which of the following data structures can be efficiently implemented using height balanced binary search tree?
A. sets
B. priority queue
C. heap
D. both sets and priority queue
Solution: Height-Balanced binary search tree can provide an efficient implementation of sets, priority queues.
Q: Two balanced binary trees are given with m and n elements respectively. They can be merged into a balanced binary search tree in ____ time.
A. O(m+n)
B. O(mn)
C. O(m)
D. O(mlog n)
Solution: First we store the in-order traversals of both the trees in two separate arrays and then we can merge these sorted sequences in O(m+n) time. And then we construct the balanced tree from this final sorted array.
Q: Which of the following is an advantage of balanced binary search tree, like AVL tree, compared to binary heap?
A. insertion takes less time
B. deletion takes less time
C. searching takes less time
D. construction of the tree takes less time than binary heap
Solution: Insertion and deletion, in both the binary heap and balanced binary search tree takes O(log n). But searching in balanced binary search tree requires O(log n) while binary heap takes O(n). Construction of balanced binary search tree takes O(nlog n) time while binary heap takes O(n).
Q: AVL trees are more balanced than Red-black trees.
A. True
B. False
C. ...
D. ...
Solution: AVL tree is more balanced than a Red-black tree because AVL tree has less height than Red-black tree given that both trees have the same number of elements.
Q: 
A. 
B. 
C. 
D. 
Solution: 

You Have Score    /10